<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Auth;

/**
 * App\Models\LiveChat
 *
 * @property int $id
 * @property int|null $uid
 * @property int $live_id
 * @property string|null $message
 * @property \Illuminate\Support\Carbon $created_at
 * @property \Illuminate\Support\Carbon $updated_at
 * @property-read \App\Models\User|null $user
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\LiveChat newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\LiveChat newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\LiveChat query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\LiveChat whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\LiveChat whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\LiveChat whereLiveId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\LiveChat whereMessage($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\LiveChat whereUid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\LiveChat whereUpdatedAt($value)
 * @mixin \Eloquent
 */
class LiveChat extends Model
{
    protected $table = 'live_chat';
    protected $primaryKey = 'id';
    protected $fillable = ['uid', 'live_id', 'message'];


    public static function boot()
    {
        parent::boot(); // TODO: Change the autogenerated stub

        static::creating(function (LiveChat $liveChat) {
            if (!isset($liveChat->uid)) {
                $liveChat->uid = intval(Auth::id());
            }
        });
    }

    public function user()
    {
        return $this->belongsTo(User::class, 'uid', 'uid');
    }
}
